package com.mtiiot.fsmanage.controller;

import com.mtiiot.fsmanage.server.MqServer;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by xyr on 2016/8/18.
 */

@SuppressWarnings("all")
@Controller
public class MqController {

    @Autowired
    MqServer mqServer;

    /**
     * 查询消息队列的元数据
     * @return
     */
    @RequestMapping(value="/mq/mqQuery.action",produces="application/json;charset=UTF-8")
    @ResponseBody
    public Object mqQuery(String sysName,String l1Name,String l2Name,String l3Name,String mqType,String times,String queryKeyWord, String mqTopic) throws Exception {
        Object obj=mqServer.mqQuery(sysName,l1Name,l2Name,l3Name,mqType,times,queryKeyWord,mqTopic);
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr=mapper.writeValueAsString(obj);
        return jsonStr;
    }

    /**
     * 统计队列数据
     * @return
     */
    @RequestMapping(value="/mq/mqStatistics.action",produces="application/json;charset=UTF-8")
    @ResponseBody
    public Object mqStatistics(String sysName,String l1Name,String l2Name,String l3Name,String mqType,String times,String mqTopic) throws Exception {
        Object obj=mqServer.mqStatistics(sysName, l1Name, l2Name, l3Name, mqType, times,mqTopic);
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr=mapper.writeValueAsString(obj);
        return jsonStr;
    }

    /**
     * 获取队列的树节点
     * @return
     */
    @RequestMapping(value="/mq/getMqChildrenNode.action",produces="application/json;charset=UTF-8")
    @ResponseBody
    public Object getMqChildrenNode(String id,String sysName,String l1Name,String l2Name ,String kafkaType, String redisType) throws Exception {
        Object obj = mqServer.getMqChildrenNode(id, sysName, l1Name, l2Name, kafkaType,redisType);
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr=mapper.writeValueAsString(obj);
        return jsonStr;
    }

    /**
     * 获得所有的主题
     * */
    @RequestMapping(value="/mq/getAllTopic.action",produces="application/json;charset=UTF-8")
    @ResponseBody
     public Object getAllTopic(String mqType) throws Exception {
        Object obj = mqServer.getAllTopic(mqType);
        ObjectMapper mapper = new ObjectMapper();
        String jsonStr = mapper.writeValueAsString(obj);
        return jsonStr;
    }

 }
